<?php

namespace App\Models;

/**
 * 需求表
 */
class Demand extends BaseModel
{
    protected $table = 'demands';

    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    // protected $fillable = [];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = [];

    protected $guarded = [];
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [];

    public function resources()
    {
        return $this->hasMany(ResourceObject::class, 'object_id', 'id')->where('type', config('project.resource.demand'));
    }
    public function types()
    {
        return $this->belongsToMany(Type::class, 'type_object_relation', 'object_id', 'type_id')->where('type', config('project.type.demand'));
    }

    public function provinces()
    {
        return $this->hasOne(Region::class, "region_id", "province_id");
    }
    public function citys()
    {
        return $this->hasOne(Region::class, "region_id", "city_id");
    }
    public function areas()
    {
        return $this->hasOne(Region::class, "region_id", "area_id");
    }
}
